﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace IWMAG.Core.EnhancedProperties
{
    public interface IPropertyMetadata
    {
        bool IsReadable { get; }
        bool IsWriteable { get; }

        bool CanSetValue { get; }
        bool CanSetComputedValue { get; }
        bool CanSetStaticResourceValue { get; }
        bool CanSetDynamicResourceValue { get; }
        bool CanSetAnimatedValue { get; }
        bool CanSetDataboundValue { get; }

        bool CanBeDatabindingSource { get; }

        bool CanProvideChangedNotifications { get; }
        bool CanProvideChangingNotifications { get; }

        bool IsFrequentAccess { get; set; }       
    }


    public static class Metadata
    {
        /// <summary>
        /// Use this method to create an IPropertyMetadata object.
        /// </summary>
        /// <param name="isReadable">Specifies if the property is readable.</param>
        /// <param name="isWriteable">Specifies if the property is writable. Note that this parameter overrides the other CanSet___Value parameters</param>
        /// <param name="canSetValue"></param>
        /// <param name="canSetComputedValue"></param>
        /// <param name="canSetAnimatedValue"></param>
        /// <param name="canSetStaticResourceValue"></param>
        /// <param name="canSetDynamicResourceValue"></param>
        /// <param name="canSetDataboundValue"></param>
        /// <param name="canBeDatabindingSource"></param>
        /// <param name="canProvideChangedNotifications"></param>
        /// <param name="canProvideChangingNotifications"></param>
        /// <param name="isFrequentAccess"></param>
        /// <returns></returns>
        public static PropertyMetadata Get(
                   bool isReadable = true,
                   bool isWriteable = true,
                   bool canSetValue = true,
                   bool canSetComputedValue = true,
                   bool canSetAnimatedValue = true,
                   bool canSetStaticResourceValue = true,
                   bool canSetDynamicResourceValue = true,
                   bool canSetDataboundValue = true,
                   bool canBeDatabindingSource = true,
                   bool canProvideChangedNotifications = true,
                   bool canProvideChangingNotifications = true,
                   bool isFrequentAccess = false
                   )
        {
            if (!isWriteable)
            {
                canSetValue = false;
                canSetComputedValue = false;
                canSetDynamicResourceValue = false;
                canSetStaticResourceValue = false;
                canSetAnimatedValue = false;
                canSetDataboundValue = false;
            }
            if (!isReadable)
            {
                canBeDatabindingSource = false;
            }

            PropertyMetadata m = new PropertyMetadata();
            m.CanSetAnimatedValue = canSetAnimatedValue;
            m.CanSetComputedValue = canSetComputedValue;
            m.IsFrequentAccess = isFrequentAccess;
            m.IsReadable = isReadable;
            m.IsWriteable = isWriteable;
            m.CanSetValue = canSetValue;
            m.CanBeDatabindingSource = canBeDatabindingSource;
            m.CanSetDataboundValue = canSetDataboundValue;
            m.CanSetDynamicResourceValue = canSetDynamicResourceValue;
            m.CanSetStaticResourceValue = canSetStaticResourceValue;
            m.CanProvideChangedNotifications = canProvideChangedNotifications;
            m.CanProvideChangingNotifications = canProvideChangingNotifications;
            return m;
        }

    }

    public class PropertyMetadata : IPropertyMetadata
    {
        internal PropertyMetadata()
        {

        }
       


        public bool IsFrequentAccess { get; set; }

        public bool CanSetAnimatedValue { get; set; }

        public bool CanSetComputedValue { get; set; }

        public bool IsReadable { get; set; }


        public bool IsWriteable { get; set; }




        public bool CanSetValue { get; set; }


        public bool CanBeDatabindingSource { get; set; }


        public bool CanProvideChangedNotifications { get; set; }

        public bool CanProvideChangingNotifications { get; set; }


        public bool CanSetStaticResourceValue { get; set; }
        public bool CanSetDynamicResourceValue { get; set; }

        public bool CanSetDataboundValue { get; set; }
    }

    
}
